package model;

import connection.DbConnection;
import bean.Answer;
import bean.Option;
import bean.Poll;
import bean.Question;

import java.sql.*;

public class CreateSAnswerImpl {
	
	
	/**
	 * Sets all PollUser javabean attributes from database (even if empty in database).
	 * 
	 * @param user is PollUser bean
	 */

		
			private static PreparedStatement st;
			private static Connection conn;
			private static ResultSet rs;
			
			public void createanswer(Answer answer){				
				try{
					rs = null;
					conn = new DbConnection().getConn();
					String sql = "insert into answer (questionid, pollid, pollversion, usernameordeviceid, text) values (";
					sql += answer.getQuestionID()+",";		
					sql += answer.getPollid()+",";	
					sql += answer.getVersion()+",";	
					sql += "'"+answer.getUsernameorDeviceID()+"',";
					sql += "'"+answer.getText()+"')";	

					st = conn.prepareStatement(sql);		
					System.out.println("createanswe sql: "+sql);
					rs=st.executeQuery();
					
				}catch(Exception e){
					e.printStackTrace();
				}
			}	
			
}